package com.eypg.action;

import java.io.File;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import com.eypg.util.ConfigUtil;
import com.eypg.util.EmailUtil;
import com.eypg.util.Struts2Utils;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 作者ryan_song E-mail:song316@gmai.com
 * @version 创建时间：2011-3-3 下午10:12:32
 * 类说明
 */
@Component
public class EmailAction extends ActionSupport{
	private static final long serialVersionUID = -6356307819518359036L;
	Log log = LogFactory.getLog(EmailAction.class);
	
	File fromFile;
	String fromFileFileName;
	String fromFileContentType;
	File toFile;
	String toFileFileName;
	String toFileContentType;
	String subject;
	String content;
	
	/**
	 * 准备群发广告邮件
	 * @return
	 */
	public String pSendAdsEmail(){
		
		return "pSendAdsEmail";
	}
	/**
	 * 群发广告邮件
	 * @return
	 */
	public String sendAdsEmail(){
		if(fromFile == null){
			String fromFilePath = ServletActionContext.getRequest()
					.getSession().getServletContext().getRealPath("/")
					+ ConfigUtil.getValue("fromEmail");
			fromFile = new File(fromFilePath);
		}
		if(toFile == null){
			String toFilePath = ServletActionContext.getRequest()
					.getSession().getServletContext().getRealPath("/")
					+ ConfigUtil.getValue("toEmail");
			toFile = new File(toFilePath);
		}
		EmailUtil.batchSendEmail(fromFile.getAbsolutePath(), toFile.getAbsolutePath(), subject, content, null);
		Struts2Utils.renderText("{\"err\":\"\",\"msg\":\"广告邮件正在发送!!!\"}");
		return null;
	}
	//setter & getter
	public File getFromFile() {
		return fromFile;
	}
	public void setFromFile(File fromFile) {
		this.fromFile = fromFile;
	}
	public String getFromFileFileName() {
		return fromFileFileName;
	}
	public void setFromFileFileName(String fromFileFileName) {
		this.fromFileFileName = fromFileFileName;
	}
	public String getFromFileContentType() {
		return fromFileContentType;
	}
	public void setFromFileContentType(String fromFileContentType) {
		this.fromFileContentType = fromFileContentType;
	}
	public File getToFile() {
		return toFile;
	}
	public void setToFile(File toFile) {
		this.toFile = toFile;
	}
	public String getToFileFileName() {
		return toFileFileName;
	}
	public void setToFileFileName(String toFileFileName) {
		this.toFileFileName = toFileFileName;
	}
	public String getToFileContentType() {
		return toFileContentType;
	}
	public void setToFileContentType(String toFileContentType) {
		this.toFileContentType = toFileContentType;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
}
